home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / oasis / oasis1-1.lha / oasis-1.1 / find.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  252 lines

  1. /*==========================================================================*
  2.     Oasis Alpha Version 1.1               (C) Copyright 1992 Fah-Chun Cheong
  3.     Revised: 5/1/92 by: fcc@eecs.umich.edu    and The University of Michigan
  4.     ------------------------------------------------------------------------
  5.     Permission to use, copy, modify, distribute, sell and resell Oasis Alpha
  6.     software and its documentation for any purpose and without fee is hereby
  7.     granted, provided that the authorship be appropriately credited and
  8.     acknowledged, and that the above copyright notice appear in all copies
  9.     and both the copyright notice and this permission notice appear in
  10.     supporting documentation. The author makes no representations about the
  11.     suitability of this software for any purpose. It is provided "as is"
  12.     without express or implied warranty. Oasis Alpha is free, caveat emptor!
  13.     ------------------------------------------------------------------------
  14.     To request Oasis Alpha source code:   oasis-alpha-request@eecs.umich.edu
  15.     To enroll in the mailing list:        oasis-alpha-request@eecs.umich.edu
  16.     To send bug reports:                  oasis-alpha-bugs@eecs.umich.edu
  17.     To discuss openly all matters Oasis:  oasis-alpha@eecs.umich.edu
  18.  *==========================================================================*/
  19. #include                "parser.h"
  20. #include                "par.h"
  21.  
  22. Spec   *find_spec(name, specs)
  23. char   *name;
  24. Spec   *specs;
  25. {
  26.         for (; specs; specs = specs->next)
  27.             if (same(name, specs->name))
  28.                 return specs;
  29.         return NUL;
  30. }
  31.  
  32. Spec   *find_base(name, specs)
  33. char   *name;
  34. Spec   *specs;
  35. {
  36.         for (; specs; specs = specs->base)
  37.             if (same(name, specs->name))
  38.                 return specs;
  39.         return NUL;
  40. }
  41.  
  42. Gene   *find_gene(name, genes)
  43. char   *name;
  44. Gene   *genes;
  45. {
  46.         for (; genes; genes = genes->next)
  47.             if (same(name, genes->name))
  48.                 return genes;
  49.         return NUL;
  50. }
  51.  
  52. Cond   *find_cond(name, conds)
  53. char   *name;
  54. Cond   *conds;
  55. {
  56.         for (; conds; conds = conds->next)
  57.             if (same(name, conds->name))
  58.                 return conds;
  59.         return NUL;
  60. }
  61.  
  62. Cst    *find_cst(name, csts)
  63. char   *name;
  64. Cst    *csts;
  65. {
  66.         for (; csts; csts = csts->next)
  67.             if (same(name, csts->name))
  68.                 return csts;
  69.         return NUL;
  70. }
  71.  
  72. Att    *find_att(name, level, prot, atts)
  73. char   *name;
  74. int     level;
  75. int     prot;
  76. Att    *atts;
  77. {
  78.         for (; atts; atts = atts->next)
  79.             if (same(name, atts->name) && seen(level, atts->level, prot, atts->prot))
  80.                 return atts;
  81.         return NUL;
  82. }
  83.  
  84. Met    *find_met(name, level, prot, mets)
  85. char   *name;
  86. int     level;
  87. int     prot;
  88. Met    *mets;
  89. {
  90.         for (; mets; mets = mets->next)
  91.             if (same(name, mets->name) && seen(level, mets->level, prot, mets->prot))
  92.                 return mets;
  93.         return NUL;
  94. }
  95.  
  96. Arg    *find_arg(name, args)
  97. char   *name;
  98. Arg    *args;
  99. {
  100.         for (; args; args = args->next)
  101.             if (same(name, args->name))
  102.                 return args;
  103.         return NUL;
  104. }
  105.  
  106. Imp    *find_imp(name, imps)
  107. char   *name;
  108. Imp    *imps;
  109. {
  110.         for (; imps; imps = imps->next)
  111.             if (same(name, imps->name))
  112.                 return imps;
  113.         return NUL;
  114. }
  115.  
  116. Head   *find_head(name, rules, rule)
  117. char   *name;
  118. Rule   *rules;
  119. Rule   *rule;
  120. {
  121.         if (rule && same(name, rule->head->name))
  122.             return NUL;
  123.         for (; rules; rules = rules->next)
  124.             if (same(name, rules->head->name))
  125.                 return rules->head;
  126.         return NUL;
  127. }
  128.  
  129. Var    *find_var(name, vars)
  130. char   *name;
  131. Var    *vars;
  132. {
  133.         for (; vars; vars = vars->next)
  134.             if (same(name, vars->name))
  135.                 return vars;
  136.         return NUL;
  137. }
  138.  
  139. Spec   *lookup_spec(name, specs, levelp, sizep, basep, genesp, condsp, cstsp, attsp, metsp)
  140. char   *name;
  141. Spec   *specs;
  142. int    *levelp;
  143. int    *sizep;
  144. Spec  **basep;
  145. Gene  **genesp;
  146. Cond  **condsp;
  147. Cst   **cstsp;
  148. Att   **attsp;
  149. Met   **metsp;
  150. {
  151.         if (specs = find_spec(name, specs)) {
  152.             *levelp = specs->level;
  153.             *sizep  = specs->size;
  154.             *genesp = specs->genes;
  155.             *condsp = specs->conds;
  156.             *cstsp  = specs->csts;
  157.             *attsp  = specs->atts;
  158.             *metsp  = specs->mets;
  159.         }
  160.         else {
  161.             *levelp = 0;
  162.             *sizep  = 0;
  163.             *genesp = NUL;
  164.             *condsp = NUL;
  165.             *cstsp  = NUL;
  166.             *attsp  = NUL;
  167.             *metsp  = NUL;
  168.         }
  169.         return *basep = specs;
  170. }
  171.  
  172. Spec   *lookup_base(name, specs, levelp, metsp)
  173. char   *name;
  174. Spec   *specs;
  175. int    *levelp;
  176. Met   **metsp;
  177. {
  178.         if (specs = find_base(name, specs)) {
  179.             *levelp = specs->level;
  180.             *metsp  = specs->mets;
  181.         }
  182.         else {
  183.             *levelp = 0;
  184.             *metsp  = NUL;
  185.         }
  186.         return specs;
  187. }
  188.  
  189. Gene   *lookup_gene(name, genes, goffp)
  190. char   *name;
  191. Gene   *genes;
  192. int    *goffp;
  193. {
  194.         if (genes = find_gene(name, genes))
  195.             *goffp = genes->goff;
  196.         else *goffp = 0;
  197.         return genes;
  198. }
  199.  
  200. Cond   *lookup_cond(name, conds, coffp)
  201. char   *name;
  202. Cond   *conds;
  203. int    *coffp;
  204. {
  205.         if (conds = find_cond(name, conds))
  206.             *coffp = conds->coff;
  207.         else *coffp = 0;
  208.         return conds;
  209. }
  210.  
  211. Att    *lookup_att(name, level, prot, atts, aoffp, typep)
  212. char   *name;
  213. int     level;
  214. int     prot;
  215. Att    *atts;
  216. int    *aoffp;
  217. Type  **typep;
  218. {
  219.         if (atts = find_att(name, level, prot, atts)) {
  220.             *aoffp = atts->aoff;
  221.             *typep = atts->type;
  222.         }
  223.         else {
  224.             *aoffp = 0;
  225.             *typep = Bot;
  226.         }
  227.         return atts;
  228. }
  229.  
  230. Met    *lookup_met(name, level, prot, mets, moffp, protp, argsp)
  231. char   *name;
  232. int     level;
  233. int     prot;
  234. Met    *mets;
  235. int    *moffp;
  236. int    *protp;
  237. Arg   **argsp;
  238. {
  239.         if (mets = find_met(name, level, prot, mets)) {
  240.             *moffp = mets->moff;
  241.             *protp = mets->prot;
  242.             *argsp = mets->args;
  243.         }
  244.         else {
  245.             *moffp = 0;
  246.             *protp = PUBLIC;
  247.             *argsp = NUL;
  248.         }
  249.         return mets;
  250. }
  251.  
  252.